/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */


package ar.com.hardcodeando.ui;
import ar.com.hardcodeando.algorithm.RSA;
import javax.swing.*;


/**
 *
 * @author Gabo
 */

public class RSAPanel extends javax.swing.JPanel {

    /**
     * Creates new form RSAPanel
     */
    private final short max_lenght_encriptar = 18;
    private final String mens_default = "TOP SECRET MESSAGE";
    private int pos_encriptar_bloque;
    private int pos_desencriptar_bloque;
    
    public RSAPanel() {
        
        initComponents();        
        
        this.rsa_aprender = new RSA();
        this.pos_encriptar_bloque = 0;
        this.pos_desencriptar_bloque = 0;
        this.RSATabbedPanel.setEnabledAt(2, false);
        this.RSATabbedPanel.setEnabledAt(3, false);
        this.RSATabbedPanel.setEnabledAt(4, false);
        this.RSATabbedPanel.setEnabledAt(5, false);
        this.RSATabbedPanel.setEnabledAt(6, false);
                
        this.spinTamBloque.setValue(1);
        this.panEncriptarBloques.setEnabled(false);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    
    private void LimpiarCalcularPaso1(){
        this.textP.setText("");
        this.textQ.setText("");
        this.textModulo.setText("");
        this.RSATabbedPanel.setEnabledAt(3, false);
        this.RSATabbedPanel.setEnabledAt(4, false);
        this.RSATabbedPanel.setEnabledAt(5, false);
        this.RSATabbedPanel.setEnabledAt(6, false);
        this.botContinuarPaso1.setEnabled(false);
        this.botContinuarPaso2.setEnabled(false);
        this.botContinuarPaso3.setEnabled(false);
        this.text_e.setText("");
        this.text_clave_publica.setText("");
        this.text_d_paso3.setText("");
        this.text_clave_privada.setText("");
    }
    
    private boolean esNumero(String cadena){
    try {
        Integer.parseInt(cadena);
        return true;
    }catch (NumberFormatException nfe){
        return false;
    }
    

}
    private void ApagarTabs(){
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, false);
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+2, false);
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+3, false);
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+4, false);                
    }
    
    private void ApagarPaso1(){
        this.textModulo.setText("");
        this.botContinuarPaso1.setEnabled(false);   
        this.botContinuarPaso1.setEnabled(false);
    }
    
    private void ApagarPaso2(){
        this.text_e.setText("");
        this.text_clave_publica.setText(""); 
        this.botContinuarPaso2.setEnabled(false);
    }
    
    private void ApagarPaso3(){
        this.text_d_paso3.setText("");
        this.text_clave_privada.setText("");
        this.botContinuarPaso3.setEnabled(false);
    }

    private void ApagarEncriptado(){
        this.textRepNum.setText("");
        this.textMensCifrado.setText("");
        this.textMensajeEncriptar.setText(this.mens_default);
        this.spinTamBloque.setValue(1);
        
        this.labelBloque.setEnabled(false);
        this.labelRepNum.setEnabled(false);        
        this.botEncriptarBloque.setEnabled(false);
        this.botTerminarEncriptar.setEnabled(false);
        this.botSigBloque.setEnabled(false);
        this.textBloqueEncriptar.setEnabled(false);
        this.textBloqueEncriptar.setText("");
        this.textASCIIencriptar.setEnabled(false);
        this.textASCIIencriptar.setText("");
        this.panEncriptarBloques.setEnabled(false);
        this.labelCuenta.setVisible(false);
        this.pos_encriptar_bloque = 0;
        
        this.textMensajeEncriptar.setEnabled(true);        
        this.spinTamBloque.setEnabled(true);
        this.botEncriptarBloques.setEnabled(true);
        this.botEncriptarTodo.setEnabled(true);
        
        this.botContinuar.setEnabled(false);
        this.botNuevoMsg.setEnabled(false);
    }
    
    private void ApagarDesencriptado(){
        this.textMensOriginalDesencriptar.setText("");
        this.textMensDescifrado.setText("");
        this.labelBloqueDes.setEnabled(false);
        this.textBloqueDesencriptar.setEnabled(false);
        this.textBloqueDesencriptar.setText("");
        this.botdesencriptarBloque.setEnabled(false);
        this.botTerminarDesencriptar.setEnabled(false);
        this.botSigBloqueDes.setEnabled(false);
        this.panDesencriptarBloques.setEnabled(false);        
        this.labelCuentaDes.setVisible(false);
        this.spinTamBloqueDes.setValue(1);
        this.botDesencriptarBloqueBloque.setEnabled(true);
        this.botDesencriptarTodo.setEnabled(true);
        this.labelCodAsciiDes.setEnabled(false);
        this.textASCIIDes.setEnabled(false);
        this.textASCIIDes.setText("");        
        this.pos_desencriptar_bloque = 0;
    }
    
    private void MostrarBloqueEncriptar(String mensaje){                     
        int tam_bloque;
        tam_bloque = (int)this.spinTamBloque.getValue();
        String bloque;
        if(this.pos_encriptar_bloque + tam_bloque < mensaje.length())
            bloque = mensaje.substring(this.pos_encriptar_bloque, this.pos_encriptar_bloque + tam_bloque);
        else
            bloque = mensaje.substring(this.pos_encriptar_bloque);
        this.textBloqueEncriptar.setText(bloque);
        this.textASCIIencriptar.setText(this.rsa_aprender.Codificar(bloque));
        String lab = "<html>Cuenta: C = " + this.textASCIIencriptar.getText() + "<sup>" + 
                this.rsa_aprender.GetE() + "</sup>mod" + this.rsa_aprender.GetModulo() + "</html>";
        this.labelCuenta.setText(lab);
        this.pos_encriptar_bloque += tam_bloque;
    }
    
    private void MostrarBloqueDesencriptar(String encriptado){
        this.textBloqueDesencriptar.setText(encriptado.substring(this.pos_desencriptar_bloque, 
                                    this.pos_desencriptar_bloque + this.rsa_aprender.GetLongitudBloque()));
        this.labelCuentaDes.setText("<html>Cuenta: " + this.textBloqueDesencriptar.getText() + "<sup>" + 
                this.rsa_aprender.GetD() + "</sup>mod" + this.rsa_aprender.GetModulo());
        this.pos_desencriptar_bloque += this.rsa_aprender.GetLongitudBloque();
    }

    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jDialog1 = new javax.swing.JDialog();
        jDialog2 = new javax.swing.JDialog();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        RSATabbedPanel = new javax.swing.JTabbedPane();
        IntroRSAPanel = new javax.swing.JPanel();
        jLabel14 = new javax.swing.JLabel();
        jLabel15 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jLabel35 = new javax.swing.JLabel();
        panelCalculosIniciales = new javax.swing.JPanel();
        jLabel18 = new javax.swing.JLabel();
        jLabel19 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel20 = new javax.swing.JLabel();
        botComenzar = new javax.swing.JButton();
        panelPaso1 = new javax.swing.JPanel();
        botPrimosAleatorio = new javax.swing.JButton();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        textP = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        textQ = new javax.swing.JTextField();
        textModulo = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        botCalcularModulo = new javax.swing.JButton();
        jLabel21 = new javax.swing.JLabel();
        botContinuarPaso1 = new javax.swing.JButton();
        panelPaso2 = new javax.swing.JPanel();
        jLabel22 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        text_p_paso2 = new javax.swing.JTextField();
        text_q_paso2 = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        textIntervalo_e = new javax.swing.JTextField();
        jLabel10 = new javax.swing.JLabel();
        text_e = new javax.swing.JTextField();
        botHallar_E = new javax.swing.JButton();
        botContinuarPaso2 = new javax.swing.JButton();
        text_clave_publica = new javax.swing.JTextField();
        jLabel11 = new javax.swing.JLabel();
        textpq = new javax.swing.JTextField();
        jLabel26 = new javax.swing.JLabel();
        panelPaso3 = new javax.swing.JPanel();
        jLabel23 = new javax.swing.JLabel();
        jLabel12 = new javax.swing.JLabel();
        text_q_paso3 = new javax.swing.JTextField();
        jLabel13 = new javax.swing.JLabel();
        jLabel16 = new javax.swing.JLabel();
        text_p_paso3 = new javax.swing.JTextField();
        text_e_paso3 = new javax.swing.JTextField();
        jLabel17 = new javax.swing.JLabel();
        text_d_paso3 = new javax.swing.JTextField();
        botHallar_D = new javax.swing.JButton();
        text_clave_privada = new javax.swing.JTextField();
        jLabel24 = new javax.swing.JLabel();
        botContinuarPaso3 = new javax.swing.JButton();
        textp1q1paso3 = new javax.swing.JTextField();
        jLabel34 = new javax.swing.JLabel();
        panelPaso4 = new javax.swing.JPanel();
        jLabel25 = new javax.swing.JLabel();
        jLabel27 = new javax.swing.JLabel();
        textMensajeEncriptar = new javax.swing.JTextField();
        jLabel28 = new javax.swing.JLabel();
        botEncriptarTodo = new javax.swing.JButton();
        botEncriptarBloques = new javax.swing.JButton();
        panEncriptarBloques = new javax.swing.JPanel();
        labelBloque = new javax.swing.JLabel();
        textBloqueEncriptar = new javax.swing.JTextField();
        labelRepNum = new javax.swing.JLabel();
        textASCIIencriptar = new javax.swing.JTextField();
        botEncriptarBloque = new javax.swing.JButton();
        botTerminarEncriptar = new javax.swing.JButton();
        botSigBloque = new javax.swing.JButton();
        labelCuenta = new javax.swing.JLabel();
        textMensCifrado = new javax.swing.JTextField();
        jLabel29 = new javax.swing.JLabel();
        labelTamBloq = new javax.swing.JLabel();
        spinTamBloque = new javax.swing.JSpinner();
        jLabel36 = new javax.swing.JLabel();
        textRepNum = new javax.swing.JTextField();
        botNuevoMsg = new javax.swing.JButton();
        botContinuar = new javax.swing.JButton();
        panelPaso5 = new javax.swing.JPanel();
        panelPaso6 = new javax.swing.JPanel();
        jLabel30 = new javax.swing.JLabel();
        jLabel31 = new javax.swing.JLabel();
        jLabel32 = new javax.swing.JLabel();
        panDesencriptarBloques = new javax.swing.JPanel();
        labelBloqueDes = new javax.swing.JLabel();
        textBloqueDesencriptar = new javax.swing.JTextField();
        botdesencriptarBloque = new javax.swing.JButton();
        botTerminarDesencriptar = new javax.swing.JButton();
        labelCuentaDes = new javax.swing.JLabel();
        botSigBloqueDes = new javax.swing.JButton();
        textASCIIDes = new javax.swing.JTextField();
        labelCodAsciiDes = new javax.swing.JLabel();
        textMensOriginalDesencriptar = new javax.swing.JTextField();
        jLabel33 = new javax.swing.JLabel();
        textMensajeCifradoDes = new javax.swing.JTextField();
        spinTamBloqueDes = new javax.swing.JSpinner();
        botDesencriptarBloqueBloque = new javax.swing.JButton();
        labelTamBloqDes = new javax.swing.JLabel();
        botDesencriptarTodo = new javax.swing.JButton();
        botReintentarDes = new javax.swing.JButton();
        textMensDescifrado = new javax.swing.JTextField();
        jLabel37 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();

        javax.swing.GroupLayout jDialog1Layout = new javax.swing.GroupLayout(jDialog1.getContentPane());
        jDialog1.getContentPane().setLayout(jDialog1Layout);
        jDialog1Layout.setHorizontalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog1Layout.setVerticalGroup(
            jDialog1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jDialog2Layout = new javax.swing.GroupLayout(jDialog2.getContentPane());
        jDialog2.getContentPane().setLayout(jDialog2Layout);
        jDialog2Layout.setHorizontalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 400, Short.MAX_VALUE)
        );
        jDialog2Layout.setVerticalGroup(
            jDialog2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel1.setText("RSA - Modo Aprender");

        RSATabbedPanel.setFocusable(false);
        RSATabbedPanel.setPreferredSize(new java.awt.Dimension(1200, 800));

        IntroRSAPanel.setPreferredSize(new java.awt.Dimension(500, 250));
        IntroRSAPanel.setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel14.setText("Introducción");
        IntroRSAPanel.add(jLabel14, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 10, -1, -1));

        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("<html>RSA es un criptosistema asimétrico que sirve tanto para encriptar mensajes como para autenticación de documentos o transacciones (Firmas Digitales).<br><br> Fue creado en 1977 por Ron Rivest, Adi Shamir y Leonard Adelman. Sus apellidos son las siglas del nombre del algoritmo. <br><br> Este criptosistema basa su seguridad en que no existe una manera rápida y sencilla de factorizar cantidades que son producto de 2 números primos grandes <br> ya que el costo computacional para encontrar números p y q es exponencial.  <br><br> Un usuario del sistema RSA crea y publica el producto de 2 grandes números, junto con un valor auxiliar, como su clave pública <br><br> Los <strong>factores primos</strong> deben mantenerse en secreto. Cualquier persona puede utilizar la clave pública para cifrar un mensaje, pero si la misma es \tlo suficientemente grande solo alguien con el conocimiento de los factores primos es factible de descifrar el mensaje <br><br> RSA codifica números, por lo tanto para encriptar mensajes debe establecerse un código numérico sobre los caracteres disponilbes para formar bloques. Nosotros utilizaremos el código ASCII. </html>");
        IntroRSAPanel.add(jLabel15, new org.netbeans.lib.awtextra.AbsoluteConstraints(20, 50, 780, 260));
        IntroRSAPanel.add(jSeparator2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, 182, 840, 0));

        jLabel35.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/rsa/RSA.png"))); // NOI18N
        IntroRSAPanel.add(jLabel35, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 320, -1, -1));

        RSATabbedPanel.addTab("Introducción", IntroRSAPanel);

        panelCalculosIniciales.setPreferredSize(new java.awt.Dimension(1800, 800));

        jLabel18.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel18.setText("Cálculos Iniciales");

        jLabel19.setText("<html>1 - Se seleccionan en forma aleatoria 2 números primos largos <strong> p </strong> y <strong> q </strong> y se calcula el producto <strong> n = p &times; q </strong>. El valor n se denomina <strong> módulo </strong>.<br><br>2 - Se elige un número denominado <strong> d </strong>, menor que el módulo calculado y que sea <strong>relativamente primo</strong> al producto de <strong>(p-1)&times;(q-1)</strong>.<br><br>3- Se calcula un número entero denominado <strong>e</strong> que esté dentro del rango <strong>1 &le; e &le; (p-1)&times;(q-1)</strong>.</html>");

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel5.setText("Conclusiones");

        jLabel20.setText("<html>La <strong>clave pública</strong> la forman la pareja <strong>(n,e)</strong> y la <strong>clave privada</strong> la forman la pareja <strong>(n,d)</strong>.<br><br>Con la clave pública se procede a encriptar el mensaje, para luego ser desencriptado con la clave privada.<br><br>Es difícil obtener la clave privada <strong>d</strong> a partir de la clave pública <strong>(n,e)</strong>. Si se logra <strong>factorizar</strong> n en p y q, podría ser obtenida.<br><br>La seguridad del RSA se basa en la idea de que esta factorización es sumamente complicada de efectuar.<br><br>La relación entre <strong>d</strong> y <strong>e</strong> asegura una correcta reconstrucción de los mensajes. Debido a que solo el receptor conoce la clave secreta <strong>d</strong> solamente él puede desencriptarlo.<br><br>Es responsabilidad del receptor mantener el secreto de la clave privada.<br><br>Este algoritmo también se utiliza para firmar documentos digitalmente. El emisor firma un mensaje utilizando su <strong>clave privada</strong> para cifrar el mensaje, y el receptor, como conoce la clave pública del emisor, procede a corroborar el mensaje desencriptando con dicha clave.</html>");

        botComenzar.setText("Comenzar");
        botComenzar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botComenzarMousePressed(evt);
            }
        });

        javax.swing.GroupLayout panelCalculosInicialesLayout = new javax.swing.GroupLayout(panelCalculosIniciales);
        panelCalculosIniciales.setLayout(panelCalculosInicialesLayout);
        panelCalculosInicialesLayout.setHorizontalGroup(
            panelCalculosInicialesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCalculosInicialesLayout.createSequentialGroup()
                .addGroup(panelCalculosInicialesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCalculosInicialesLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(panelCalculosInicialesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, 780, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 780, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel18)
                            .addComponent(jLabel5)))
                    .addGroup(panelCalculosInicialesLayout.createSequentialGroup()
                        .addGap(793, 793, 793)
                        .addComponent(botComenzar)))
                .addContainerGap(933, Short.MAX_VALUE))
        );
        panelCalculosInicialesLayout.setVerticalGroup(
            panelCalculosInicialesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelCalculosInicialesLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel18)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel19, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 31, Short.MAX_VALUE)
                .addGroup(panelCalculosInicialesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelCalculosInicialesLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel20, javax.swing.GroupLayout.PREFERRED_SIZE, 237, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(298, 298, 298))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelCalculosInicialesLayout.createSequentialGroup()
                        .addComponent(botComenzar)
                        .addGap(251, 251, 251))))
        );

        RSATabbedPanel.addTab("Cálculos Iniciales", panelCalculosIniciales);

        panelPaso1.setEnabled(false);

        botPrimosAleatorio.setText("Aleatorio");
        botPrimosAleatorio.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botPrimosAleatorioMousePressed(evt);
            }
        });
        botPrimosAleatorio.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botPrimosAleatorioActionPerformed(evt);
            }
        });

        jLabel2.setText("<html>Como primera medida tenemos que hallar los dos números primos para luego calcular el módulo. <br><br>Por lo general deben ser números muy grandes del orden de los 100 dígitos para que sea muy dificil romper el criptosistema. Hasta el año 2012 se recomendaba usar<br> números primos tales que su módulo sea de 2000 bits.<br><br> Para fines didáticos usaremos números primos no tan grandes, tomando como valor mínimo el número 601 y como valor máximo 811. <br><br>Esto es para asegurar que el módulo tenga como mínimo 6 dígitos, ya que usaremos hasta 2 bloques para encriptar ya que cada caracter se representa con 3 dígitos<br> por tomar como referencia el código ASCII. </html>");

        jLabel3.setText("p");

        textP.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textPActionPerformed(evt);
            }
        });

        jLabel4.setText("q");

        textQ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textQActionPerformed(evt);
            }
        });

        textModulo.setEditable(false);
        textModulo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textModuloActionPerformed(evt);
            }
        });

        jLabel6.setText("<html>Módulo n = p &times; q</html>");

        botCalcularModulo.setText("Calcular");
        botCalcularModulo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botCalcularModuloMousePressed(evt);
            }
        });

        jLabel21.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel21.setText("Paso 1: Hallar el módulo");

        botContinuarPaso1.setText("Continuar");
        botContinuarPaso1.setEnabled(false);
        botContinuarPaso1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botContinuarPaso1MousePressed(evt);
            }
        });
        botContinuarPaso1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botContinuarPaso1ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout panelPaso1Layout = new javax.swing.GroupLayout(panelPaso1);
        panelPaso1.setLayout(panelPaso1Layout);
        panelPaso1Layout.setHorizontalGroup(
            panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso1Layout.createSequentialGroup()
                .addGroup(panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPaso1Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel21)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPaso1Layout.createSequentialGroup()
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textP, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textQ, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(401, 401, 401))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPaso1Layout.createSequentialGroup()
                        .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textModulo, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(botContinuarPaso1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(botCalcularModulo, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(botPrimosAleatorio, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(316, 316, 316)))
                .addContainerGap(1000, Short.MAX_VALUE))
        );
        panelPaso1Layout.setVerticalGroup(
            panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso1Layout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jLabel21)
                .addGap(18, 18, 18)
                .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(67, 67, 67)
                .addGroup(panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textP, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textQ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4)
                    .addComponent(jLabel3)
                    .addComponent(botPrimosAleatorio))
                .addGap(11, 11, 11)
                .addGroup(panelPaso1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textModulo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botCalcularModulo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(botContinuarPaso1)
                .addContainerGap(362, Short.MAX_VALUE))
        );

        RSATabbedPanel.addTab("Paso 1", panelPaso1);

        jLabel22.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel22.setText("Paso 2: Hallar componente e.");

        jLabel7.setText("<html>En este paso buscaremos un valor numérico al que llamaremos <strong>e</strong>. Este valor será junto con el módulo hallado en el paso anterior la <strong>clave pública</strong> para poder encriptar.<br><br>Este valor debe ser relativamente primo al producto (p-1)&times;(q-1).<br><br>Escogeremos un valor perteneciente al intervalo <strong>[max(p,q)+1,n-1]</strong>. Por lo tanto, se debe cumplir<strong> MCD [e,(p-1)&times;(q-1)] = 1</strong><br><br>El par <strong>(n,e)</strong> será la clave pública que se utilizará para realizar los cálculos para encriptar mensajes.</html>");

        jLabel8.setText("p");

        text_p_paso2.setEditable(false);
        text_p_paso2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                text_p_paso2ActionPerformed(evt);
            }
        });

        text_q_paso2.setEditable(false);

        jLabel9.setText("q");

        textIntervalo_e.setEditable(false);
        textIntervalo_e.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textIntervalo_eActionPerformed(evt);
            }
        });

        jLabel10.setText("Intervalo");

        text_e.setEditable(false);

        botHallar_E.setText("Hallar e");
        botHallar_E.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botHallar_EMousePressed(evt);
            }
        });

        botContinuarPaso2.setText("Continuar");
        botContinuarPaso2.setEnabled(false);
        botContinuarPaso2.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botContinuarPaso2MousePressed(evt);
            }
        });

        text_clave_publica.setEditable(false);

        jLabel11.setText("Clave Pública");

        textpq.setEditable(false);

        jLabel26.setText("<html>(p-1)&times;(q-1)</html>");

        javax.swing.GroupLayout panelPaso2Layout = new javax.swing.GroupLayout(panelPaso2);
        panelPaso2.setLayout(panelPaso2Layout);
        panelPaso2Layout.setHorizontalGroup(
            panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso2Layout.createSequentialGroup()
                .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPaso2Layout.createSequentialGroup()
                        .addGap(210, 210, 210)
                        .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel11)
                            .addComponent(jLabel10)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(panelPaso2Layout.createSequentialGroup()
                                .addComponent(text_p_paso2, javax.swing.GroupLayout.PREFERRED_SIZE, 62, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel9)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(text_q_paso2, javax.swing.GroupLayout.DEFAULT_SIZE, 60, Short.MAX_VALUE))
                            .addComponent(textIntervalo_e)
                            .addComponent(text_e)
                            .addComponent(text_clave_publica))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(botHallar_E, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(botContinuarPaso2)
                            .addGroup(panelPaso2Layout.createSequentialGroup()
                                .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(textpq, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelPaso2Layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel22))))
                .addContainerGap(983, Short.MAX_VALUE))
        );
        panelPaso2Layout.setVerticalGroup(
            panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso2Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addComponent(jLabel22)
                .addGap(18, 18, 18)
                .addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 30, Short.MAX_VALUE)
                .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel8)
                    .addComponent(text_p_paso2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel9)
                    .addComponent(text_q_paso2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel26, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textpq, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textIntervalo_e, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel10))
                .addGap(15, 15, 15)
                .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text_e, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botHallar_E))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel11)
                    .addComponent(text_clave_publica, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botContinuarPaso2))
                .addContainerGap(399, Short.MAX_VALUE))
        );

        RSATabbedPanel.addTab("Paso 2", panelPaso2);

        jLabel23.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel23.setText("Paso 3: Hallar componente d.");

        jLabel12.setText("<html>Lo que hay que hacer luego de hallar la clave pública, es hallar un valor entero <strong>d</strong> que será junto con el módulo encontrado en el paso 1 la <strong>clave privada</strong> y servirá para realizar los cálculos para desencriptar los mensajes.<br><br>Este valor debe estar dentro del rango <strong>1 &le; d &le; (p-1)&times;(q-1)</strong><br><br>Por lo tanto aplicaremos la siguiente ecuación, en donde buscaremos el valor de <strong>d</strong>:<br><br><strong>e &times; d = 1 mod [(p-1) &times; (q-1)]</strong> &rarr; <strong>d</strong> es el multiplicador modular inverso de <strong>e mod[(p-1) &times; (q-1)]</strong></html>");

        text_q_paso3.setEditable(false);
        text_q_paso3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                text_q_paso3ActionPerformed(evt);
            }
        });

        jLabel13.setText("p");

        jLabel16.setText("q");

        text_p_paso3.setEditable(false);
        text_p_paso3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                text_p_paso3ActionPerformed(evt);
            }
        });

        text_e_paso3.setEditable(false);
        text_e_paso3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                text_e_paso3ActionPerformed(evt);
            }
        });

        jLabel17.setText("e");

        text_d_paso3.setEditable(false);
        text_d_paso3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                text_d_paso3ActionPerformed(evt);
            }
        });

        botHallar_D.setText("Hallar d");
        botHallar_D.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botHallar_DMousePressed(evt);
            }
        });

        text_clave_privada.setEditable(false);

        jLabel24.setText("Clave Privada");

        botContinuarPaso3.setText("Continuar");
        botContinuarPaso3.setEnabled(false);
        botContinuarPaso3.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botContinuarPaso3MousePressed(evt);
            }
        });

        textp1q1paso3.setEditable(false);

        jLabel34.setText("<html>(p-1)&times;(q-1)</html>");

        javax.swing.GroupLayout panelPaso3Layout = new javax.swing.GroupLayout(panelPaso3);
        panelPaso3.setLayout(panelPaso3Layout);
        panelPaso3Layout.setHorizontalGroup(
            panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso3Layout.createSequentialGroup()
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPaso3Layout.createSequentialGroup()
                        .addGap(20, 20, 20)
                        .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel23)))
                    .addGroup(panelPaso3Layout.createSequentialGroup()
                        .addGap(226, 226, 226)
                        .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPaso3Layout.createSequentialGroup()
                                .addComponent(jLabel13)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(text_p_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(10, 10, 10)
                                .addComponent(jLabel16)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(text_q_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(65, 65, 65))
                            .addGroup(panelPaso3Layout.createSequentialGroup()
                                .addComponent(jLabel17)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(text_e_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(panelPaso3Layout.createSequentialGroup()
                        .addGap(166, 166, 166)
                        .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel24)
                            .addComponent(jLabel34, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(panelPaso3Layout.createSequentialGroup()
                                .addComponent(text_clave_privada, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botContinuarPaso3))
                            .addComponent(textp1q1paso3, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelPaso3Layout.createSequentialGroup()
                                .addComponent(text_d_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, 146, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(botHallar_D, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                .addContainerGap(731, Short.MAX_VALUE))
        );
        panelPaso3Layout.setVerticalGroup(
            panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso3Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel23)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel12, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPaso3Layout.createSequentialGroup()
                        .addGap(33, 33, 33)
                        .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(text_p_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(text_q_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel16)))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelPaso3Layout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel13)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text_e_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel17))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel34, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(textp1q1paso3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text_d_paso3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botHallar_D))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(text_clave_privada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel24)
                    .addComponent(botContinuarPaso3))
                .addContainerGap(392, Short.MAX_VALUE))
        );

        textp1q1paso3.getAccessibleContext().setAccessibleName("");

        RSATabbedPanel.addTab("Paso 3", panelPaso3);

        jLabel25.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel25.setText("Paso 4: Encriptar.");

        jLabel27.setText("<html>Para encriptar mensajes, primero definiremos una asociación numérica para cada caracter.<br><br>En nuestro caso, utilizaremos el código ASCII, por ejemplo <strong>A = 065 , a = 097, etc.</strong> (Notar que como ASCII tiene 255 códigos,  cada caracter <br> estará representado por 3 dígitos, tanto del mensaje original como del mensaje encriptado).<br><br>Podemos codificar caracter por caracter, aplicando su código numérico, o tomar bloques de mayor cantidad de caracteres y codificar de a grupos. <br>Limitaremos por cuestiones didácticas el tamaño máximo de bloque a 2 y el mensaje a encriptar a 18 caracteres.<br><br>Cada grupo de caracteres se encripta  con la siguiente fórmula: <strong>C = M<sup>e</sup>mod n</strong> donde M es el valor del grupo de caracteres, C el valor encriptado,<br> e y n los componentes de la clave pública.</html>");

        textMensajeEncriptar.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textMensajeEncriptar.setText("TOP SECRET MESSAGE");
        textMensajeEncriptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textMensajeEncriptarActionPerformed(evt);
            }
        });

        jLabel28.setText("Mensaje Original:");

        botEncriptarTodo.setText("Encriptar Todo");
        botEncriptarTodo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botEncriptarTodoMousePressed(evt);
            }
        });

        botEncriptarBloques.setText("Encriptar Bloque a Bloque");
        botEncriptarBloques.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botEncriptarBloquesMousePressed(evt);
            }
        });
        botEncriptarBloques.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botEncriptarBloquesActionPerformed(evt);
            }
        });

        panEncriptarBloques.setEnabled(false);

        labelBloque.setText("Bloque:");
        labelBloque.setEnabled(false);

        textBloqueEncriptar.setEditable(false);
        textBloqueEncriptar.setEnabled(false);

        labelRepNum.setText("Representación numérica:");
        labelRepNum.setEnabled(false);

        textASCIIencriptar.setEditable(false);
        textASCIIencriptar.setEnabled(false);

        botEncriptarBloque.setText("Encriptar Bloque");
        botEncriptarBloque.setEnabled(false);
        botEncriptarBloque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botEncriptarBloqueMousePressed(evt);
            }
        });
        botEncriptarBloque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botEncriptarBloqueActionPerformed(evt);
            }
        });

        botTerminarEncriptar.setText("Terminar");
        botTerminarEncriptar.setEnabled(false);
        botTerminarEncriptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botTerminarEncriptarMousePressed(evt);
            }
        });

        botSigBloque.setText("Siguiente Bloque");
        botSigBloque.setEnabled(false);
        botSigBloque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botSigBloqueMousePressed(evt);
            }
        });
        botSigBloque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botSigBloqueActionPerformed(evt);
            }
        });

        labelCuenta.setForeground(new java.awt.Color(204, 0, 0));
        labelCuenta.setText("Cuenta:");

        javax.swing.GroupLayout panEncriptarBloquesLayout = new javax.swing.GroupLayout(panEncriptarBloques);
        panEncriptarBloques.setLayout(panEncriptarBloquesLayout);
        panEncriptarBloquesLayout.setHorizontalGroup(
            panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panEncriptarBloquesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(panEncriptarBloquesLayout.createSequentialGroup()
                        .addComponent(labelBloque)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textBloqueEncriptar, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(labelRepNum))
                    .addComponent(labelCuenta))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(textASCIIencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, 170, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botTerminarEncriptar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(botEncriptarBloque, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botSigBloque)
                .addContainerGap(109, Short.MAX_VALUE))
        );
        panEncriptarBloquesLayout.setVerticalGroup(
            panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panEncriptarBloquesLayout.createSequentialGroup()
                .addGap(52, 52, 52)
                .addGroup(panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelBloque)
                    .addComponent(textBloqueEncriptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelRepNum)
                    .addComponent(botEncriptarBloque)
                    .addComponent(textASCIIencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botSigBloque))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panEncriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botTerminarEncriptar)
                    .addComponent(labelCuenta))
                .addContainerGap())
        );

        textMensCifrado.setEditable(false);
        textMensCifrado.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        textMensCifrado.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textMensCifrado.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textMensCifradoActionPerformed(evt);
            }
        });

        jLabel29.setText("Mensaje Cifrado:");

        labelTamBloq.setText("Tamaño bloque:");

        spinTamBloque.setModel(new javax.swing.SpinnerNumberModel(1, 1, 2, 1));

        jLabel36.setText("<html>Representación<br>numérica</html>");

        textRepNum.setEditable(false);

        botNuevoMsg.setText("Nuevo Mensaje");
        botNuevoMsg.setEnabled(false);
        botNuevoMsg.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botNuevoMsgMousePressed(evt);
            }
        });

        botContinuar.setText("Continuar");
        botContinuar.setEnabled(false);
        botContinuar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botContinuarMousePressed(evt);
            }
        });

        javax.swing.GroupLayout panelPaso4Layout = new javax.swing.GroupLayout(panelPaso4);
        panelPaso4.setLayout(panelPaso4Layout);
        panelPaso4Layout.setHorizontalGroup(
            panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso4Layout.createSequentialGroup()
                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(panelPaso4Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(panEncriptarBloques, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(panelPaso4Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelPaso4Layout.createSequentialGroup()
                                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(jLabel28)
                                        .addComponent(jLabel36, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(labelTamBloq, javax.swing.GroupLayout.Alignment.TRAILING)
                                    .addComponent(jLabel29, javax.swing.GroupLayout.Alignment.TRAILING))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                    .addGroup(panelPaso4Layout.createSequentialGroup()
                                        .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                            .addGroup(panelPaso4Layout.createSequentialGroup()
                                                .addComponent(spinTamBloque, javax.swing.GroupLayout.PREFERRED_SIZE, 68, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 582, Short.MAX_VALUE)
                                                .addComponent(botNuevoMsg))
                                            .addGroup(panelPaso4Layout.createSequentialGroup()
                                                .addComponent(textMensajeEncriptar, javax.swing.GroupLayout.PREFERRED_SIZE, 319, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(18, 18, 18)
                                                .addComponent(botEncriptarBloques, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addComponent(botEncriptarTodo, javax.swing.GroupLayout.PREFERRED_SIZE, 169, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(0, 0, Short.MAX_VALUE)))
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(botContinuar, javax.swing.GroupLayout.PREFERRED_SIZE, 95, javax.swing.GroupLayout.PREFERRED_SIZE))
                                    .addComponent(textRepNum)
                                    .addComponent(textMensCifrado)))
                            .addGroup(panelPaso4Layout.createSequentialGroup()
                                .addGap(1, 1, 1)
                                .addComponent(jLabel25)))))
                .addContainerGap(835, Short.MAX_VALUE))
        );
        panelPaso4Layout.setVerticalGroup(
            panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso4Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel25)
                .addGap(18, 18, 18)
                .addComponent(jLabel27, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(35, 35, 35)
                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textMensajeEncriptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel28)
                    .addComponent(botEncriptarBloques)
                    .addComponent(botEncriptarTodo))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel36, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelPaso4Layout.createSequentialGroup()
                        .addGap(3, 3, 3)
                        .addComponent(textRepNum, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textMensCifrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel29))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(panelPaso4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(spinTamBloque, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTamBloq)
                    .addComponent(botNuevoMsg)
                    .addComponent(botContinuar))
                .addGap(18, 18, 18)
                .addComponent(panEncriptarBloques, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(252, 252, 252))
        );

        RSATabbedPanel.addTab("Paso 4", panelPaso4);

        jLabel30.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel30.setText("Paso 5: Desencriptar.");

        jLabel31.setText("<html>Una vez que el receptor recibe un mensaje encriptado, procede a desencriptarlo a través de su clave privada. <br><br>La fórmula para efectuar el proceso es: <strong>M = C<sup>d</sup>mod n</strong> donde C es el valor numérico de los caracteres encriptados, M el valor numérico del mensaje original que se acaba de desencriptar,<br>(los valores numéricos son los códigos ASCII para nuestros ejemplos), d y n los componentes de la clave privada.</html>");

        jLabel32.setText("Mensaje Cifrado:");

        panDesencriptarBloques.setEnabled(false);

        labelBloqueDes.setText("Bloque:");
        labelBloqueDes.setEnabled(false);

        textBloqueDesencriptar.setEditable(false);
        textBloqueDesencriptar.setEnabled(false);

        botdesencriptarBloque.setText("Desencriptar Bloque");
        botdesencriptarBloque.setEnabled(false);
        botdesencriptarBloque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botdesencriptarBloqueMousePressed(evt);
            }
        });
        botdesencriptarBloque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botdesencriptarBloqueActionPerformed(evt);
            }
        });

        botTerminarDesencriptar.setText("Terminar");
        botTerminarDesencriptar.setEnabled(false);
        botTerminarDesencriptar.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botTerminarDesencriptarMousePressed(evt);
            }
        });

        labelCuentaDes.setForeground(new java.awt.Color(204, 0, 0));
        labelCuentaDes.setText("Cuenta:");

        botSigBloqueDes.setText("Siguiente Bloque");
        botSigBloqueDes.setEnabled(false);
        botSigBloqueDes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botSigBloqueDesMousePressed(evt);
            }
        });
        botSigBloqueDes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botSigBloqueDesActionPerformed(evt);
            }
        });

        textASCIIDes.setEditable(false);
        textASCIIDes.setEnabled(false);

        labelCodAsciiDes.setText("Codigo ASCII:");
        labelCodAsciiDes.setEnabled(false);

        javax.swing.GroupLayout panDesencriptarBloquesLayout = new javax.swing.GroupLayout(panDesencriptarBloques);
        panDesencriptarBloques.setLayout(panDesencriptarBloquesLayout);
        panDesencriptarBloquesLayout.setHorizontalGroup(
            panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panDesencriptarBloquesLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(panDesencriptarBloquesLayout.createSequentialGroup()
                        .addComponent(labelBloqueDes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(textBloqueDesencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, 177, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(botdesencriptarBloque)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED))
                    .addGroup(panDesencriptarBloquesLayout.createSequentialGroup()
                        .addComponent(labelCuentaDes)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(labelCodAsciiDes)
                        .addGap(17, 17, 17)))
                .addGroup(panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(botSigBloqueDes, javax.swing.GroupLayout.DEFAULT_SIZE, 129, Short.MAX_VALUE)
                    .addComponent(textASCIIDes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botTerminarDesencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(48, Short.MAX_VALUE))
        );
        panDesencriptarBloquesLayout.setVerticalGroup(
            panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panDesencriptarBloquesLayout.createSequentialGroup()
                .addGap(35, 35, 35)
                .addGroup(panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelBloqueDes)
                    .addComponent(textBloqueDesencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(botdesencriptarBloque)
                    .addComponent(botSigBloqueDes)
                    .addComponent(botTerminarDesencriptar))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 18, Short.MAX_VALUE)
                .addGroup(panDesencriptarBloquesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(labelCuentaDes)
                    .addComponent(textASCIIDes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelCodAsciiDes))
                .addContainerGap())
        );

        textMensOriginalDesencriptar.setEditable(false);
        textMensOriginalDesencriptar.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textMensOriginalDesencriptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textMensOriginalDesencriptarActionPerformed(evt);
            }
        });

        jLabel33.setText("Mensaje Original:");

        textMensajeCifradoDes.setEditable(false);
        textMensajeCifradoDes.setFont(new java.awt.Font("Verdana", 0, 11)); // NOI18N
        textMensajeCifradoDes.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        textMensajeCifradoDes.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                textMensajeCifradoDesActionPerformed(evt);
            }
        });

        spinTamBloqueDes.setEnabled(false);

        botDesencriptarBloqueBloque.setText("Desencriptar Bloque a Bloque");
        botDesencriptarBloqueBloque.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botDesencriptarBloqueBloqueMousePressed(evt);
            }
        });
        botDesencriptarBloqueBloque.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botDesencriptarBloqueBloqueActionPerformed(evt);
            }
        });

        labelTamBloqDes.setText("Tamaño bloque:");

        botDesencriptarTodo.setText("Desencriptar Todo");
        botDesencriptarTodo.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botDesencriptarTodoMousePressed(evt);
            }
        });
        botDesencriptarTodo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                botDesencriptarTodoActionPerformed(evt);
            }
        });

        botReintentarDes.setText("Reintentar");
        botReintentarDes.setEnabled(false);
        botReintentarDes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                botReintentarDesMousePressed(evt);
            }
        });

        textMensDescifrado.setEditable(false);

        jLabel37.setText("Mensaje Descifrado:");

        javax.swing.GroupLayout panelPaso6Layout = new javax.swing.GroupLayout(panelPaso6);
        panelPaso6.setLayout(panelPaso6Layout);
        panelPaso6Layout.setHorizontalGroup(
            panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso6Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel30)
                    .addComponent(jLabel31, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(panDesencriptarBloques, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(panelPaso6Layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jLabel32)
                            .addComponent(jLabel37)
                            .addComponent(jLabel33)
                            .addComponent(labelTamBloqDes))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(textMensajeCifradoDes, javax.swing.GroupLayout.PREFERRED_SIZE, 837, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(panelPaso6Layout.createSequentialGroup()
                                    .addComponent(spinTamBloqueDes, javax.swing.GroupLayout.PREFERRED_SIZE, 82, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGap(18, 18, 18)
                                    .addComponent(botDesencriptarBloqueBloque)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(botReintentarDes, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(botDesencriptarTodo, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)))
                                .addComponent(textMensDescifrado, javax.swing.GroupLayout.DEFAULT_SIZE, 488, Short.MAX_VALUE)
                                .addComponent(textMensOriginalDesencriptar)))))
                .addContainerGap(432, Short.MAX_VALUE))
        );
        panelPaso6Layout.setVerticalGroup(
            panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso6Layout.createSequentialGroup()
                .addGap(25, 25, 25)
                .addComponent(jLabel30)
                .addGap(18, 18, 18)
                .addComponent(jLabel31, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(15, 15, 15)
                .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel32)
                    .addComponent(textMensajeCifradoDes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textMensDescifrado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel37))
                .addGap(7, 7, 7)
                .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(textMensOriginalDesencriptar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel33))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelPaso6Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(botDesencriptarTodo)
                    .addComponent(botDesencriptarBloqueBloque)
                    .addComponent(spinTamBloqueDes, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(labelTamBloqDes))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(botReintentarDes)
                .addGap(18, 18, 18)
                .addComponent(panDesencriptarBloques, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(301, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout panelPaso5Layout = new javax.swing.GroupLayout(panelPaso5);
        panelPaso5.setLayout(panelPaso5Layout);
        panelPaso5Layout.setHorizontalGroup(
            panelPaso5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(panelPaso6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(406, Short.MAX_VALUE))
        );
        panelPaso5Layout.setVerticalGroup(
            panelPaso5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelPaso5Layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(panelPaso6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );

        RSATabbedPanel.addTab("Paso 5", panelPaso5);

        jButton4.setText("Cerrar");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(383, 383, 383)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 1164, Short.MAX_VALUE)
                .addComponent(jButton4)
                .addContainerGap())
            .addComponent(RSATabbedPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 1812, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jButton4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(RSATabbedPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 736, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(76, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 0, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(0, 14, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 14, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jButton4ActionPerformed

    private void botComenzarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botComenzarMousePressed
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, true);
        this.RSATabbedPanel.setSelectedIndex(this.RSATabbedPanel.getSelectedIndex()+1);
    }//GEN-LAST:event_botComenzarMousePressed

    private void text_q_paso3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_q_paso3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_text_q_paso3ActionPerformed

    private void text_p_paso3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_p_paso3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_text_p_paso3ActionPerformed

    private void text_d_paso3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_d_paso3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_text_d_paso3ActionPerformed

    private void botContinuarPaso3MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botContinuarPaso3MousePressed
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, true);
        this.RSATabbedPanel.setSelectedIndex(this.RSATabbedPanel.getSelectedIndex()+1);
    }//GEN-LAST:event_botContinuarPaso3MousePressed

    private void botContinuarPaso2MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botContinuarPaso2MousePressed
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, true);
        this.RSATabbedPanel.setSelectedIndex(this.RSATabbedPanel.getSelectedIndex()+1);
        this.text_p_paso3.setText(Long.toString(this.rsa_aprender.GetP()));
        this.text_q_paso3.setText(Long.toString(this.rsa_aprender.GetQ()));
        this.text_e_paso3.setText(Long.toString(this.rsa_aprender.GetE()));
        this.textp1q1paso3.setText(Long.toString(this.rsa_aprender.GetP1Q1()));
    }//GEN-LAST:event_botContinuarPaso2MousePressed

    private void textIntervalo_eActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textIntervalo_eActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textIntervalo_eActionPerformed

    private void text_p_paso2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_p_paso2ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_text_p_paso2ActionPerformed

    private void botContinuarPaso1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botContinuarPaso1ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botContinuarPaso1ActionPerformed

    private void botContinuarPaso1MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botContinuarPaso1MousePressed
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, true);
        this.RSATabbedPanel.setSelectedIndex(this.RSATabbedPanel.getSelectedIndex()+1);
        this.text_p_paso2.setText(Long.toString(this.rsa_aprender.GetP()));
        this.text_q_paso2.setText(Long.toString(this.rsa_aprender.GetQ()));
        this.textpq.setText(Long.toString(this.rsa_aprender.GetP1Q1()));
        this.textIntervalo_e.setText("(" + Long.toString(this.rsa_aprender.GetIntervaloInfD()) + "," + 
                Long.toString(this.rsa_aprender.GetIntervaloSupD()) + ")");
    }//GEN-LAST:event_botContinuarPaso1MousePressed

    private void botCalcularModuloMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botCalcularModuloMousePressed
        String p = this.textP.getText();
        String q = this.textQ.getText();
        int max_primo = this.rsa_aprender.GetMaxPrimo();
        int min_primo = this.rsa_aprender.GetMinPrimo();
        if(p.isEmpty() || q.isEmpty() )
        {
            JOptionPane.showMessageDialog(null, "Ingrese números primos p y q para calcular el módulo");
            this.LimpiarCalcularPaso1();
        }
        else
        {
            if (!this.esNumero(p) || !this.esNumero(q))
            {
                JOptionPane.showMessageDialog(null, "Debe ingresar valores numéricos");
                this.LimpiarCalcularPaso1();
            }
            else
            {
                long pe = Long.parseLong(p);
                long qu = Long.parseLong(q);
                if(!this.rsa_aprender.SetP(pe)){
                    JOptionPane.showMessageDialog(null, p + " no es un número primo");
                    this.LimpiarCalcularPaso1();
                }
                else{
                    if(!this.rsa_aprender.SetQ(qu)){
                        JOptionPane.showMessageDialog(null, q + " no es un número primo");
                        this.LimpiarCalcularPaso1();
                    }
                    else{
                        if(pe > max_primo || qu > max_primo || pe < min_primo || qu < min_primo){
                            JOptionPane.showMessageDialog(null, "Para fines didácticos, los números primos "
                            + "deben estar comprendidos entre " + min_primo + " y "+ max_primo);
                            this.LimpiarCalcularPaso1();
                        }
                        else{
                            if(pe == qu){
                                JOptionPane.showMessageDialog(null, "Elegir p y q distintos.");
                                this.LimpiarCalcularPaso1();
                            }
                            else{
                                this.rsa_aprender.GenerarModulo();                            
                                this.textModulo.setText(Long.toString(this.rsa_aprender.ObtenerModulo()));
                                this.botContinuarPaso1.setEnabled(true);                               
                            }
                        }
                    }
                }                               
            }
        }
    }//GEN-LAST:event_botCalcularModuloMousePressed

    private void textModuloActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textModuloActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textModuloActionPerformed

    private void textQActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textQActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textQActionPerformed

    private void textPActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textPActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textPActionPerformed

    private void botPrimosAleatorioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botPrimosAleatorioActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botPrimosAleatorioActionPerformed

    private void botPrimosAleatorioMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botPrimosAleatorioMousePressed
        this.rsa_aprender.GenerarPrimos();
        this.textP.setText(Long.toString(this.rsa_aprender.GetP()));
        this.textQ.setText(Long.toString(this.rsa_aprender.GetQ()));
        
        this.ApagarTabs();
        this.ApagarPaso1();
        this.ApagarPaso2();
        this.ApagarPaso3();
        this.ApagarEncriptado();  
        this.ApagarDesencriptado();
    }//GEN-LAST:event_botPrimosAleatorioMousePressed

    private void text_e_paso3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_text_e_paso3ActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_text_e_paso3ActionPerformed

    private void botHallar_EMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botHallar_EMousePressed
        this.rsa_aprender.GenerarExponentePublico();
        this.text_e.setText(Long.toString(this.rsa_aprender.GetE()));
        this.text_clave_publica.setText("(" + Long.toString(this.rsa_aprender.GetModulo()) + "," +
                Long.toString(this.rsa_aprender.GetE()) + ")");
        this.botContinuarPaso2.setEnabled(true);
    }//GEN-LAST:event_botHallar_EMousePressed

    private void botHallar_DMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botHallar_DMousePressed
        this.rsa_aprender.GenerarExponentePrivado();
        this.text_d_paso3.setText(Long.toString(this.rsa_aprender.GetD()));
        this.text_clave_privada.setText("(" + Long.toString(this.rsa_aprender.GetModulo()) + 
                "," + Long.toString(this.rsa_aprender.GetD()) + ")");
        this.botContinuarPaso3.setEnabled(true);
    }//GEN-LAST:event_botHallar_DMousePressed

    private void botContinuarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botContinuarMousePressed
        this.RSATabbedPanel.setEnabledAt(this.RSATabbedPanel.getSelectedIndex()+1, true);
        this.RSATabbedPanel.setSelectedIndex(this.RSATabbedPanel.getSelectedIndex()+1);
        this.spinTamBloqueDes.setValue(this.spinTamBloque.getValue());        
        this.textMensajeCifradoDes.setText(this.textMensCifrado.getText());
    }//GEN-LAST:event_botContinuarMousePressed

    private void textMensCifradoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textMensCifradoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textMensCifradoActionPerformed

    private void botEncriptarBloqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botEncriptarBloqueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botEncriptarBloqueActionPerformed

    private void botEncriptarBloquesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botEncriptarBloquesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botEncriptarBloquesActionPerformed

    private void botEncriptarBloquesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botEncriptarBloquesMousePressed
        String mensaje = this.textMensajeEncriptar.getText();
        if(mensaje.length() > this.max_lenght_encriptar){
            JOptionPane.showMessageDialog(null, "Por cuestiones didácticas ingrese mensaje mas cortos, "
                    + "hasta " + this.max_lenght_encriptar + " caracteres.");
            this.textMensajeEncriptar.setText(this.mens_default);
            this.textRepNum.setText("");
            this.textMensCifrado.setText("");
        }
        else{
            this.labelBloque.setEnabled(true);
            this.labelRepNum.setEnabled(true);        
            this.botEncriptarBloque.setEnabled(true);
            this.botTerminarEncriptar.setEnabled(true);
            this.textBloqueEncriptar.setEnabled(true);
            this.textASCIIencriptar.setEnabled(true);
            this.panEncriptarBloques.setEnabled(true);
            this.labelCuenta.setVisible(true);

            this.textMensajeEncriptar.setEnabled(false);
            this.textMensCifrado.setText("");
            this.textRepNum.setText("");
            this.spinTamBloque.setEnabled(false);
            this.botEncriptarTodo.setEnabled(false);
            this.botEncriptarBloques.setEnabled(false);

            this.MostrarBloqueEncriptar(mensaje);
        }
    }//GEN-LAST:event_botEncriptarBloquesMousePressed

    private void botEncriptarTodoMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botEncriptarTodoMousePressed
        String mensaje = this.textMensajeEncriptar.getText();
        if(mensaje.length() > this.max_lenght_encriptar){
            JOptionPane.showMessageDialog(null, "Por cuestiones didácticas ingrese mensaje mas cortos, "
                    + "hasta " + this.max_lenght_encriptar + " caracteres.");
            this.textMensajeEncriptar.setText(this.mens_default);
            this.textRepNum.setText("");
            this.textMensCifrado.setText("");
        }
        else{
            String msg = this.rsa_aprender.Encrypt(mensaje, (int)this.spinTamBloque.getValue());          
            this.textMensCifrado.setText(msg);            
            this.textRepNum.setText(this.rsa_aprender.Codificar(mensaje));
            this.botEncriptarBloques.setEnabled(false);
            this.botEncriptarTodo.setEnabled(false);
            this.textMensajeEncriptar.setEnabled(false);
            this.spinTamBloque.setEnabled(false);
            this.botContinuar.setEnabled(true);
            this.botNuevoMsg.setEnabled(true);
            JOptionPane.showMessageDialog(null, "El mensaje ha sido encriptado.");
        }
    }//GEN-LAST:event_botEncriptarTodoMousePressed

    private void textMensajeEncriptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textMensajeEncriptarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textMensajeEncriptarActionPerformed

    private void botSigBloqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botSigBloqueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botSigBloqueActionPerformed

    private void botEncriptarBloqueMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botEncriptarBloqueMousePressed
        String msg = this.rsa_aprender.Encrypt(this.textBloqueEncriptar.getText(), (int)this.spinTamBloque.getValue());
        this.textMensCifrado.setText(this.textMensCifrado.getText() + msg);
        String aux = this.textRepNum.getText() + this.textASCIIencriptar.getText();        
        this.textRepNum.setText(aux);
        this.botSigBloque.setEnabled(true);
        this.botEncriptarBloque.setEnabled(false);
    }//GEN-LAST:event_botEncriptarBloqueMousePressed

    private void botSigBloqueMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botSigBloqueMousePressed
        String mensaje = this.textMensajeEncriptar.getText();
        if(this.pos_encriptar_bloque < mensaje.length()){
            this.MostrarBloqueEncriptar(mensaje);
            this.botEncriptarBloque.setEnabled(true);
            this.botSigBloque.setEnabled(false);
        }
        else{
            JOptionPane.showMessageDialog(null, "El mensaje ha sido encriptado.");
            this.botSigBloque.setEnabled(false);
            this.botTerminarEncriptar.setEnabled(false);
            this.botContinuar.setEnabled(true);
            this.botNuevoMsg.setEnabled(true);
        }                
    }//GEN-LAST:event_botSigBloqueMousePressed

    private void botNuevoMsgMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botNuevoMsgMousePressed
        this.ApagarEncriptado();
        this.RSATabbedPanel.setEnabledAt(6, false);
        this.ApagarDesencriptado();
    }//GEN-LAST:event_botNuevoMsgMousePressed

    private void botTerminarEncriptarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botTerminarEncriptarMousePressed
        String mensaje = this.textMensajeEncriptar.getText();
        String encriptado = this.rsa_aprender.Encrypt(mensaje, (int)this.spinTamBloque.getValue());
        this.textMensCifrado.setText(encriptado);
        this.textRepNum.setText(this.rsa_aprender.Codificar(mensaje));
        JOptionPane.showMessageDialog(null, "El mensaje ha sido encriptado.");
        this.botSigBloque.setEnabled(false);
        this.botTerminarEncriptar.setEnabled(false);
        this.botContinuar.setEnabled(true);
        this.botNuevoMsg.setEnabled(true);
        
    }//GEN-LAST:event_botTerminarEncriptarMousePressed

    private void botDesencriptarTodoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botDesencriptarTodoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botDesencriptarTodoActionPerformed

    private void botDesencriptarTodoMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botDesencriptarTodoMousePressed
        String aux = this.rsa_aprender.DesencriptarTodo
                                (this.textMensajeCifradoDes.getText(),(int)this.spinTamBloqueDes.getValue());
        this.textMensOriginalDesencriptar.setText(this.rsa_aprender.DecodificarAscii(aux));
        this.textMensDescifrado.setText(aux);
        this.botDesencriptarTodo.setEnabled(false);
        this.botDesencriptarBloqueBloque.setEnabled(false);
        JOptionPane.showMessageDialog(null, "El mensaje ha sido desencriptado");
        this.botReintentarDes.setEnabled(true);
    }//GEN-LAST:event_botDesencriptarTodoMousePressed

    private void botDesencriptarBloqueBloqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botDesencriptarBloqueBloqueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botDesencriptarBloqueBloqueActionPerformed

    private void botDesencriptarBloqueBloqueMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botDesencriptarBloqueBloqueMousePressed
        this.labelBloqueDes.setEnabled(true);
        this.labelCuentaDes.setVisible(true);
        this.textBloqueDesencriptar.setEnabled(true);
        this.botdesencriptarBloque.setEnabled(true);
        this.botTerminarDesencriptar.setEnabled(true);
        this.botDesencriptarTodo.setEnabled(false);
        this.botDesencriptarBloqueBloque.setEnabled(false);
        this.MostrarBloqueDesencriptar(this.textMensajeCifradoDes.getText());
        this.labelCodAsciiDes.setEnabled(true);
        this.textASCIIDes.setEnabled(true);
    }//GEN-LAST:event_botDesencriptarBloqueBloqueMousePressed

    private void textMensajeCifradoDesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textMensajeCifradoDesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textMensajeCifradoDesActionPerformed

    private void textMensOriginalDesencriptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_textMensOriginalDesencriptarActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_textMensOriginalDesencriptarActionPerformed

    private void botdesencriptarBloqueActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botdesencriptarBloqueActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botdesencriptarBloqueActionPerformed

    private void botSigBloqueDesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botSigBloqueDesMousePressed
        String mensaje = this.textMensajeCifradoDes.getText();
        if(this.pos_desencriptar_bloque < mensaje.length()){
            this.MostrarBloqueDesencriptar(mensaje);
            this.textASCIIDes.setText("");
            this.botdesencriptarBloque.setEnabled(true);
            this.botSigBloqueDes.setEnabled(false);
        }
        else{
            JOptionPane.showMessageDialog(null, "El mensaje ha sido desencriptado");
            this.botSigBloqueDes.setEnabled(false);
            this.botdesencriptarBloque.setEnabled(false);
            this.botReintentarDes.setEnabled(true);
            this.botTerminarDesencriptar.setEnabled(false);
            this.pos_desencriptar_bloque = 0;
        }
    }//GEN-LAST:event_botSigBloqueDesMousePressed

    private void botSigBloqueDesActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_botSigBloqueDesActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_botSigBloqueDesActionPerformed

    private void botTerminarDesencriptarMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botTerminarDesencriptarMousePressed
        
        this.textMensOriginalDesencriptar.setText(this.rsa_aprender.DesencriptarTodo
        (this.textMensajeCifradoDes.getText(), (int)this.spinTamBloqueDes.getValue()));
        this.botdesencriptarBloque.setEnabled(false);
        this.botSigBloqueDes.setEnabled(false);
        this.botTerminarDesencriptar.setEnabled(false);
        JOptionPane.showMessageDialog(null, "El mensaje ha sido desencriptado");
        this.botReintentarDes.setEnabled(true);
        this.pos_desencriptar_bloque = 0;
    }//GEN-LAST:event_botTerminarDesencriptarMousePressed

    private void botReintentarDesMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botReintentarDesMousePressed
        this.ApagarDesencriptado();
        this.botReintentarDes.setEnabled(false);
        this.spinTamBloqueDes.setValue(this.spinTamBloque.getValue());
    }//GEN-LAST:event_botReintentarDesMousePressed

    private void botdesencriptarBloqueMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_botdesencriptarBloqueMousePressed
        int tam_bloque = (int)this.spinTamBloqueDes.getValue();
        String desenc = this.rsa_aprender.DesencriptarTodo(this.textBloqueDesencriptar.getText(), tam_bloque);
        String decod = this.rsa_aprender.DecodificarAscii(desenc);
        this.textASCIIDes.setText(desenc);
        this.textMensOriginalDesencriptar.setText(this.textMensOriginalDesencriptar.getText() + decod);
        this.textMensDescifrado.setText(this.textMensDescifrado.getText() + desenc);
        this.botdesencriptarBloque.setEnabled(false);
        this.botSigBloqueDes.setEnabled(true);
    }//GEN-LAST:event_botdesencriptarBloqueMousePressed

    private final RSA rsa_aprender;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JPanel IntroRSAPanel;
    private javax.swing.JTabbedPane RSATabbedPanel;
    private javax.swing.JButton botCalcularModulo;
    private javax.swing.JButton botComenzar;
    private javax.swing.JButton botContinuar;
    private javax.swing.JButton botContinuarPaso1;
    private javax.swing.JButton botContinuarPaso2;
    private javax.swing.JButton botContinuarPaso3;
    private javax.swing.JButton botDesencriptarBloqueBloque;
    private javax.swing.JButton botDesencriptarTodo;
    private javax.swing.JButton botEncriptarBloque;
    private javax.swing.JButton botEncriptarBloques;
    private javax.swing.JButton botEncriptarTodo;
    private javax.swing.JButton botHallar_D;
    private javax.swing.JButton botHallar_E;
    private javax.swing.JButton botNuevoMsg;
    private javax.swing.JButton botPrimosAleatorio;
    private javax.swing.JButton botReintentarDes;
    private javax.swing.JButton botSigBloque;
    private javax.swing.JButton botSigBloqueDes;
    private javax.swing.JButton botTerminarDesencriptar;
    private javax.swing.JButton botTerminarEncriptar;
    private javax.swing.JButton botdesencriptarBloque;
    private javax.swing.JButton jButton4;
    private javax.swing.JDialog jDialog1;
    private javax.swing.JDialog jDialog2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel14;
    private javax.swing.JLabel jLabel15;
    private javax.swing.JLabel jLabel16;
    private javax.swing.JLabel jLabel17;
    private javax.swing.JLabel jLabel18;
    private javax.swing.JLabel jLabel19;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel20;
    private javax.swing.JLabel jLabel21;
    private javax.swing.JLabel jLabel22;
    private javax.swing.JLabel jLabel23;
    private javax.swing.JLabel jLabel24;
    private javax.swing.JLabel jLabel25;
    private javax.swing.JLabel jLabel26;
    private javax.swing.JLabel jLabel27;
    private javax.swing.JLabel jLabel28;
    private javax.swing.JLabel jLabel29;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel30;
    private javax.swing.JLabel jLabel31;
    private javax.swing.JLabel jLabel32;
    private javax.swing.JLabel jLabel33;
    private javax.swing.JLabel jLabel34;
    private javax.swing.JLabel jLabel35;
    private javax.swing.JLabel jLabel36;
    private javax.swing.JLabel jLabel37;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JLabel labelBloque;
    private javax.swing.JLabel labelBloqueDes;
    private javax.swing.JLabel labelCodAsciiDes;
    private javax.swing.JLabel labelCuenta;
    private javax.swing.JLabel labelCuentaDes;
    private javax.swing.JLabel labelRepNum;
    private javax.swing.JLabel labelTamBloq;
    private javax.swing.JLabel labelTamBloqDes;
    private javax.swing.JPanel panDesencriptarBloques;
    private javax.swing.JPanel panEncriptarBloques;
    private javax.swing.JPanel panelCalculosIniciales;
    private javax.swing.JPanel panelPaso1;
    private javax.swing.JPanel panelPaso2;
    private javax.swing.JPanel panelPaso3;
    private javax.swing.JPanel panelPaso4;
    private javax.swing.JPanel panelPaso5;
    private javax.swing.JPanel panelPaso6;
    private javax.swing.JSpinner spinTamBloque;
    private javax.swing.JSpinner spinTamBloqueDes;
    private javax.swing.JTextField textASCIIDes;
    private javax.swing.JTextField textASCIIencriptar;
    private javax.swing.JTextField textBloqueDesencriptar;
    private javax.swing.JTextField textBloqueEncriptar;
    private javax.swing.JTextField textIntervalo_e;
    private javax.swing.JTextField textMensCifrado;
    private javax.swing.JTextField textMensDescifrado;
    private javax.swing.JTextField textMensOriginalDesencriptar;
    private javax.swing.JTextField textMensajeCifradoDes;
    private javax.swing.JTextField textMensajeEncriptar;
    private javax.swing.JTextField textModulo;
    private javax.swing.JTextField textP;
    private javax.swing.JTextField textQ;
    private javax.swing.JTextField textRepNum;
    private javax.swing.JTextField text_clave_privada;
    private javax.swing.JTextField text_clave_publica;
    private javax.swing.JTextField text_d_paso3;
    private javax.swing.JTextField text_e;
    private javax.swing.JTextField text_e_paso3;
    private javax.swing.JTextField text_p_paso2;
    private javax.swing.JTextField text_p_paso3;
    private javax.swing.JTextField text_q_paso2;
    private javax.swing.JTextField text_q_paso3;
    private javax.swing.JTextField textp1q1paso3;
    private javax.swing.JTextField textpq;
    // End of variables declaration//GEN-END:variables
}
